﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using RogueWarrior.View;
using RogueWarrior.Controller;

namespace RogueWarrior
{
    class Character : IEntity
    {
        Vector2 mPlayerPosition;
        DisplayableEntity mDisplayableEntity;
        CharacterController mCharacterController;

        public Character(DisplayableEntity displayableEntity, CharacterController characterController)
        {
            mDisplayableEntity = displayableEntity;
            mCharacterController = characterController;
        }


        public void setPlayerPosition(Vector2 playerPosition)
        {
            mPlayerPosition = playerPosition;
        }

        public Vector2 getPlayerPosition()
        {
            return mPlayerPosition;
        }

        public DisplayableEntity getDisplayableEntity()
        {
            return mDisplayableEntity;
        }


        /// <summary>
        /// This is called when Update() is called as part of the game loop to update the playerSprite's position
        /// </summary>
        /// <param name="currentPlayerOneState">Provides the game pad state of player one's controller.</param>
        public void updatePlayer(GamePadState currentPlayerOneState)
        {
            Vector2 newPosition = mCharacterController.update(currentPlayerOneState, getPlayerPosition());

            if (newPosition != this.getPlayerPosition())
            {
                this.setPlayerPosition(newPosition);
                if (this.mCharacterController.getLeftThumbstickDirection() == "E")
                {
                    if (this.mCharacterController.getIsRunning())
                    {
                        this.mDisplayableEntity.setRowNumber(4);
                    }
                    else
                    {
                        this.mDisplayableEntity.setRowNumber(1);

                    }
                }
                else if (this.mCharacterController.getLeftThumbstickDirection() == "SE")
                {
                    if (this.mCharacterController.getIsRunning())
                    {
                        this.mDisplayableEntity.setRowNumber(9);
                    }
                    else
                    {
                        this.mDisplayableEntity.setRowNumber(6);

                    }
                }
                else if (this.mCharacterController.getLeftThumbstickDirection() == "S")
                {
                    if (this.mCharacterController.getIsRunning())
                    {
                        this.mDisplayableEntity.setRowNumber(14);
                    }
                    else
                    {
                        this.mDisplayableEntity.setRowNumber(10);

                    }
                }

            }               
            else
            {
                this.mDisplayableEntity.setRowNumber(0);
            }
            mDisplayableEntity.update();

        }

    }
}
